package com.example.administrator.wallet.adapter;

import android.content.Context;
import android.content.res.Resources;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.example.administrator.wallet.R;
import com.example.administrator.wallet.model.bean.QueryCoinBean;
import com.example.administrator.wallet.view.activity.asset.QueryCoinActivity;

import java.util.List;

/**
 * Effect:
 * <p>
 * Author:  CaiYapeng
 * <p>
 * Time  :  2018/8/2.
 */
public class QueryCoinAdapter extends BaseAdapter {
    private Context context;
    private List<QueryCoinBean.DataBean> mDatas;
    private QueryCoinBean.DataBean dataBean;
    private final Resources resources;
    private OnClickPosition click;

    public QueryCoinAdapter(QueryCoinActivity queryCoinActivity, List<QueryCoinBean.DataBean> mDatas) {
        this.context = queryCoinActivity;
        this.mDatas = mDatas;

        resources = context.getResources();
    }

    @Override
    public int getCount() {
        return mDatas.size();
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        final ViewHolder holder;
        if (view == null) {
            holder = new ViewHolder();
            view = View.inflate(context, R.layout.item_query_list, null);
            view.setTag(holder);
        } else {
            holder = (ViewHolder) view.getTag();
        }

        holder.coin_icon = (ImageView) view.findViewById(R.id.coin_icon);
        holder.coin_name = (TextView) view.findViewById(R.id.coin_name);
        holder.coin_pName = (TextView) view.findViewById(R.id.coin_pName);
        holder.isAdd = (TextView) view.findViewById(R.id.isAdd);

        dataBean = mDatas.get(i);
        Glide.with(context).load(dataBean.getIcon()).into(holder.coin_icon);
        holder.coin_name.setText(dataBean.getSymbol());
        holder.coin_pName.setText(dataBean.getUnit());
        if (dataBean.getStatus() == 0) {
            holder.isAdd.setSelected(false);
            holder.isAdd.setTextColor(resources.getColor(R.color.statu));
            holder.isAdd.setText(R.string.add);
        } else {
            holder.isAdd.setSelected(true);
            holder.isAdd.setTextColor(resources.getColor(R.color.colorprompt));
            holder.isAdd.setText(R.string.already_add);
        }

        holder.isAdd.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                click.getPosition(dataBean);
            }
        });
        return view;
    }

    private class ViewHolder {
        private ImageView coin_icon;
        private TextView coin_name;
        private TextView coin_pName;
        private TextView isAdd;
    }


    public void position(OnClickPosition click) {
        this.click = click;
    }


    public interface OnClickPosition {
        void getPosition(QueryCoinBean.DataBean bean);
    }
}
